#include "EntityFileReader.h"

EntityFileReader::EntityFileReader(){}
EntityFileReader::~EntityFileReader(){}
Entity* EntityFileReader::GetEntity(unsigned int entity_type){
	Entity * e = new Entity();
	//find the file based on the int type
	const unsigned int total_digits = 8;
	char entity_number_string[total_digits];
	for(int i = 0; i < total_digits; i++)
		entity_number_string[i] = '\0';
	sprintf(entity_number_string, "%d", entity_type);

	char path[MAX_PATH_LENGTH];

	for(int i = 0; i < MAX_PATH_LENGTH; i++)
		path[i] = '\0';

	strcat(path, ENTITY_DIRECTORY);
	strcat(path, entity_number_string);
	strcat(path, ENTITY_EXTENSION);	

	//open the file
	OpenFile(path);
	
	//tokenize the file
	TokenizeFile();

	//assign the fields to the entity
	for(unsigned int i = 0; i < GetTotalTokens(); i++){
		if(GetToken(i) == "height"){
			int int_value = atoi(GetToken(i+2).c_str());
			e->SetH(int_value);
		}
		if(GetToken(i) == "width"){
			int int_value = atoi(GetToken(i+2).c_str());
			e->SetW(int_value);
		}
	}
		

	//add the entity to the list
	//return the entity address 

	Entity::AddToEntityList(e);
	
	return e;
	

	
}